package main

import "fmt"

//暴力解法:4ms 77%，3MB 95%
func minArray1(numbers []int) int {
	for i := 0; i < len(numbers)-1; i++ {
		if numbers[i] > numbers[i+1] {
			return numbers[i+1]
		}
	}
	return numbers[0]
}

//二分查找:4ms 77%，3MB 95%
func minArray(numbers []int) int {
	l, r := 0, len(numbers)-1
	for l < r {
		m := (l + r) / 2
		if numbers[m] > numbers[r] {
			l = m + 1
		} else if numbers[m] < numbers[r] {
			r = m
		} else {
			r--
		}
	}
	return numbers[l]
}

func main() {
	fmt.Println(minArray1([]int{0}))
	fmt.Println(minArray([]int{3, 1, 3}))
}
